//let server = require("./server");
// npm run build -- --report
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = ['js', 'css']

function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  runtimeCompiler: true,

  configureWebpack: config => {
    config.resolve.alias['vue$']='vue/dist/vue.common'
    if (process.env.NODE_ENV === 'production') {
      return {
        plugins: [
          new CompressionPlugin({
            test: /\.js$|\.css/,
            threshold: 10240,
            deleteOriginalAssets: false
          })
        ]
      }
    }
  },

  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',

  devServer: {
    proxy: {
      '/': {
        target: '//jsonplaceholder.typicode.com/posts/', //对应的端口
        changeOrigin: true,
      }
    }
  },

  // 生产环境是否生成 sourceMap 文件
  productionSourceMap: false,

  css: {
    loaderOptions: { //预加载scss,其他组件可以引用该变量
      scss: {
        prependData: `
          @import "~@/assets/scss/_mixin.scss";
        `
      },
      less: {}
    }
  },

  chainWebpack: config => {
    config.module
      .rule('images')
      .use('url-loader')
      .loader('url-loader')
      .tap(options => Object.assign(options, {
        limit: 10240,
        fallback: {
          loader: 'file-loader',
          options: {
            name: 'images/[name].[hash:8].[ext]'
          }
        }
      })).end()
    config.module
      .rule('vue')
      //.test(/iview.min.js$/)
      .test(/\.vue$/)
      .use('iview-loader')
      .loader('iview-loader')
      .tap(() => {
        return {
          prefix: true
        }
      })
  },
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [
        resolve('./src/assets/less/var.less')
        //path.resolve(__dirname, './src/assets/less/var.less')
      ]
    }
  }
}
